

#NOTE THAT gee assumes the data frame is sorted according to the id variable, so SORT IT / MAKE SURE IT'S SORTED!!!
install.packages('gee')
install.packages('geepack')
library(geepack)
library(gee)



#####This is for the case-level regressions
rm(mydata)
mydata <- read.csv(file.choose(), header = T)

#all data
mymodel <- gee(outcome.P ~ PTO + DCT_P + DCT_C + X1plusPOb + X2plusPOb + X3POb + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = panelid, family = binomial, corstr = 'exchangeable', scale.fix = TRUE)
summary(mymodel)
mymodel <- gee(outcome.P ~ PTO + DCT_P + DCT_C + numPobserved + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = panelid, family = binomial, corstr = 'exchangeable', scale.fix = TRUE)
summary(mymodel)
mymodel <- gee(outcome.P ~ PTO + DCT_P + DCT_C + X1plusR + X2plusR + X3R + X1plusTB + X2plusTB + X3TB + X1plusPOb + X2plusPOb + X3POb + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = panelid, family = binomial, corstr = 'exchangeable', scale.fix = TRUE)
summary(mymodel)

mymodel <- gee(outcome.C ~ PTO + DCT_P + DCT_C + X1plusPOb + X2plusPOb + X3POb + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = panelid, family = binomial, corstr = 'exchangeable', scale.fix = TRUE)
summary(mymodel)
mymodel <- gee(outcome.C ~ PTO + DCT_P + DCT_C + numPobserved + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = panelid, family = binomial, corstr = 'exchangeable', scale.fix = TRUE)
summary(mymodel)
mymodel <- gee(outcome.C ~ PTO + DCT_P + DCT_C + X1plusR + X2plusR + X3R + X1plusTB + X2plusTB + X3TB + X1plusPOb + X2plusPOb + X3POb + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = panelid, family = binomial, corstr = 'exchangeable', scale.fix = TRUE)
summary(mymodel)

mymodel <- gee(Precedential ~ PTO + DCT_P + DCT_C + X1plusPOb + X2plusPOb + X3POb + outcome.M + outcome.C + X1plusPOb*outcome.C + X2plusPOb*outcome.C + X3POb*outcome.C + X1plusPOb*outcome.M + X2plusPOb*outcome.M + X3POb*outcome.M + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = panelid, family = binomial, corstr = 'exchangeable', scale.fix = TRUE)
summary(mymodel)
mymodel <- gee(Precedential ~ PTO + DCT_P + DCT_C + numPobserved + numPobserved*outcome.C + numPobserved*outcome.M + outcome.M + outcome.C + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = panelid, family = binomial, corstr = 'exchangeable', scale.fix = TRUE)
summary(mymodel)
mymodel <- gee(Precedential ~ PTO + Affirmed + X1plusR + X2plusR + X3R + X1plusTB + X2plusTB + X3TB + X1plusPOb + X2plusPOb + X3POb + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = panelid, family = binomial, corstr = 'exchangeable', scale.fix = TRUE)
summary(mymodel)

mymodel <- gee(R36 ~ PTO + DCT_P + DCT_C + X1plusPOb + X2plusPOb + X3POb + X1plusPOb*outcome.C + X2plusPOb*outcome.C + X3POb*outcome.C + X1plusPOb*outcome.M + X2plusPOb*outcome.M + X3POb*outcome.M + outcome.M + outcome.C + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = panelid, family = binomial, corstr = 'exchangeable', scale.fix = TRUE)
summary(mymodel)
mymodel <- gee(R36 ~ PTO + DCT_P + DCT_C + numPobserved + numPobserved*outcome.C + numPobserved*outcome.M + outcome.M + outcome.C + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = panelid, family = binomial, corstr = 'exchangeable', scale.fix = TRUE)
summary(mymodel)
mymodel <- gee(R36 ~ PTO + Affirmed + X1plusR + X2plusR + X3R + X1plusTB + X2plusTB + X3TB + X1plusPOb + X2plusPOb + X3POb + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = panelid, family = binomial, corstr = 'exchangeable', scale.fix = TRUE)
summary(mymodel)

#authorship
rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.P ~ PTO + DCT_P + DCT_C + author_EB + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = judgeid, family = 'binomial', corstr = 'independence', scale.fix = TRUE)
summary(mymodel)
rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.P ~ PTO + DCT_P + DCT_C + author_EB + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = panelid, family = 'binomial', corstr = 'independence' , scale.fix = TRUE)
summary(mymodel)


#####Vote level regressions
rm(mydata)
str(mydata)

#all VOTES 

rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.P ~ PTO + DCT_P + DCT_C + judge.ideology + numotherPOb + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = caseid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)
rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.P ~ PTO + DCT_P + DCT_C + judge.ideology + numotherPOb + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = judgeid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)

rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.P ~ PTO + DCT_P + DCT_C + judge.ideology + X1plusotherPOb + X2otherPOb + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = caseid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)
rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.P ~ PTO + DCT_P + DCT_C + judge.ideology + X1plusotherPOb + X2otherPOb + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = judgeid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)

rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.C ~ PTO + DCT_P + DCT_C + judge.ideology + numotherPOb + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = caseid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)
rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.C ~ PTO + DCT_P + DCT_C + judge.ideology + numotherPOb + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = judgeid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)

rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.C ~ PTO + DCT_P + DCT_C + judge.ideology + X1plusotherPOb + X2otherPOb + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = caseid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)
rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.C ~ PTO + DCT_P + DCT_C + judge.ideology + X1plusotherPOb + X2otherPOb + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = judgeid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)






#Using all judges as datapoints, case level
rm(mydata)
mydata <- read.csv(file.choose(), header = T)

mymodel <- glm(outcome.P ~ Prost + Bryson + Plager + Mayer + Schall + Hughes + Wallach + Reyna + Chen + Clevenger + Linn + Stoll + Taranto + O.Malley + Moore + Newman  + Rader + Lourie + Dyk + PTO + DCT_P + DCT_C + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, family = 'binomial')
summary(mymodel)


#using all judges as datapoints, vote level
rm(mydata)
mydata <- read.csv(file.choose(), header = T)

mymodel <- gee(outcome.P ~ RaderV + ProstV + LourieV + BrysonV + PlagerV + MayerV + SchallV + HughesV + WallachV + ReynaV + ChenV + ClevengerV + LinnV + StollV + TarantoV + O.MalleyV + MooreV + NewmanV + Prost + Lourie + Bryson + Plager + Mayer + Schall + Hughes + Wallach + Reyna + Chen + Clevenger + Linn + Stoll + Taranto + O.Malley + Newman + Rader + Moore + PTO + DCT_P + DCT_C +  + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = caseid, family = binomial, corstr = 'exchangeable', scale.fix = TRUE)
summary(mymodel)


#VOTING political background, patent-related background

rm(mydata)
mydata <- read.csv(file.choose(), header = T)
str(mydata)

#all VOTES
rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.P ~ PTO + DCT_P + DCT_C + judge.TB + judge.R + numotherTB + numotherR + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = caseid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)
rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.P ~ PTO + DCT_P + DCT_C + judge.TB + judge.R + numotherTB + numotherR + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = judgeid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)

rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.P ~ PTO + DCT_P + DCT_C + judge.TB + judge.R + X1plusotherTB + X2otherTB + X1plusotherR + X2otherR + judge.TB*X1plusotherTB + judge.TB*X2otherTB + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = caseid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)
rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.P ~ PTO + DCT_P + DCT_C + judge.TB + judge.R + X1plusotherTB + X2otherTB + X1plusotherR + X2otherR + judge.TB*X1plusotherTB + judge.TB*X2otherTB + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = judgeid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)



rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.P.val ~ PTO + DCT_P + DCT_C + judge.TB + judge.R + X1plusotherTB + X2otherTB + X1plusotherR + X2otherR + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = caseid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)
rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.P.val ~ PTO + DCT_P + DCT_C + judge.TB + judge.R + X1plusotherTB + X2otherTB + X1plusotherR + X2otherR + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = judgeid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)



rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.P ~ PTO + DCT_P + DCT_C + judge.PB + judge.R + numotherPB + numotherR + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = caseid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)
rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.P ~ PTO + DCT_P + DCT_C + judge.PB + judge.R + numotherPB + numotherR + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = judgeid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)

rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.P ~ PTO + DCT_P + DCT_C + judge.PB + judge.R + X1plusotherPB + X2otherPB + X1plusotherR + X2otherR + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = caseid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)
rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.P ~ PTO + DCT_P + DCT_C + judge.PB + judge.R + X1plusotherPB + X2otherPB + X1plusotherR + X2otherR + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = judgeid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)



rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.C ~ PTO + DCT_P + DCT_C + judge.TB + judge.R + numotherTB + numotherR + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = caseid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)
rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.C ~ PTO + DCT_P + DCT_C + judge.TB + judge.R + numotherTB + numotherR + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = judgeid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)

rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.C ~ PTO + DCT_P + DCT_C + judge.TB + judge.R + X1plusotherTB + X2otherTB + X1plusotherR + X2otherR + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = caseid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)
rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.C ~ PTO + DCT_P + DCT_C + judge.TB + judge.R + X1plusotherTB + X2otherTB + X1plusotherR + X2otherR + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = judgeid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)

rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.C ~ PTO + DCT_P + DCT_C + judge.PB + judge.R + numotherPB + numotherR + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = caseid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)
rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.C ~ PTO + DCT_P + DCT_C + judge.PB + judge.R + numotherPB + numotherR + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = judgeid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)

rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.C ~ PTO + DCT_P + DCT_C + judge.PB + judge.R + X1plusotherPB + X2otherPB + X1plusotherR + X2otherR + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = caseid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)
rm(mydata)
mydata <- read.csv(file.choose(), header = T)
mymodel <- gee(outcome.C ~ PTO + DCT_P + DCT_C + judge.PB + judge.R + X1plusotherPB + X2otherPB + X1plusotherR + X2otherR + X2015 + X2016 + X2017 + X2018 + X2019 + X2020 + X2021, data = mydata, id = judgeid, family = binomial, corstr = 'independence', scale.fix = TRUE)
summary(mymodel)





